﻿#include "PreWindow3D.h" 
#include <QHBoxLayout>
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKComponents.h"
#include "FITK_Kernel/FITKAppFramework/FITKComponentInterface.h"
#include "FITK_Component/FITKRenderWindowVTK/FITKGraph3DWindowInterface.h"
#include "FITK_Component/FITKRenderWindowVTK/FITKGraph3DWindowVTK.h"

namespace GUI
{
    PreWindow3D::PreWindow3D(GraphArea* parent /*= nullptr*/)
        :GraphAbstractSubWin(parent)
    {
        _pushButton->setText("3D");
        this->setWindowTitle("3D");
        QHBoxLayout* lay = new QHBoxLayout(this);
        lay->setMargin(0);
 
        //从组件获取3D窗口
        AppFrame::FITKComponentInterface* comp = FITKAPP->getComponents()
            ->getComponentByName("Graph3DWindowVTK");
        QWidget* w = comp->getWidget(1);

        //强制类型转换
        _renderWindow = dynamic_cast<Comp::FITKGraph3DWindowVTK*>(w);
        
        if (_renderWindow)
        {
            double position[3]{ 1,1,1 };
            double focalPoint[3]{ 0,0,0 };
            double viewUp[3]{ 0,0,1 };
            //设置视角
            _renderWindow->setDefaultView(focalPoint, viewUp, position);
            _renderWindow->setISOView(focalPoint, viewUp, position);
            //关闭VTK警告
            _renderWindow->SetGlobalWarningDisplay(false);
        }
        
        lay->addWidget(_renderWindow);
        this->setLayout(lay);

    }

    PreWindow3D::~PreWindow3D()
    {
        if (_renderWindow) delete _renderWindow;
    }

    Comp::FITKGraph3DWindowVTK* PreWindow3D::getRenderWindow()
    {
        return _renderWindow;
    }

    GUI::GraphAbstractSubWin::SubWinType PreWindow3D::getSubWindowType()
    {
        return GraphAbstractSubWin::Pre3D;
    }

} 

